package wqh.dao;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import wqh.domain.GeoBuilding;

import java.util.List;

/**
 * Created by devts on 2016/9/25.
 */
public interface GeoBuildingDao {

    @Select("SELECT * FROM geo_building")
    List<GeoBuilding> findAllRecord();

    @Select("SELECT * FROM geo_building WHERE id = #{1}")
    GeoBuilding findRecordById(Integer id);

    @Update("UPDATE geo_building SET name = #{name}, parent_id = #{parent_id}, level = #{level}, " +
            "pos_x = #{pos_x}, pos_y = #{pos_y}, picture = #{picture}, description = #{description} WHERE " +
            "id = #{id}")
    int updateRecord(GeoBuilding geoBuilding);

    @Insert("INSERT INTO geo_building (name, parent_id, level, pos_x, pos_y, picture, description) " +
            "VALUES(#{name}, #{parent_id}, #{level}, #{pos_x}, #{pos_y}, #{picture}, #{description})")
    int insertRecord(GeoBuilding geoBuilding);

    @Delete("DELETE FROM geo_building WHERE id = #{1}")
    int deleteRecord(Integer id);

    @Select("select * from geo_building where parent_id =#{1}")
    GeoBuilding findAllByParentID(Integer id);

    @Select("select * from geo_building where name = #{0} and level = #{1}")
    List<GeoBuilding> findAllByNameAndLevel(String name, Byte level);

    @Select("select * from geo_building where name = #{0} and parent_id = #{1}")
    List<GeoBuilding> findAllByNameAndParentID(String name, Integer parentID);

    @Select("select * from geo_building where name = #{0} and parent_id = #{1} and level = #{2}")
    List<GeoBuilding> findAllByNameAndParentIDAndLevel(String name, Integer parentID, Byte level);

    @Update("UPDATE geo_building SET picture = #{0} WHERE id = #{1}")
    int updateMap(String picture, Integer id);


    String findNameById(Integer id);
}
